package util

import (
	"fmt"
	"os"
	"github.com/go-kit/kit/log"
	"github.com/go-kit/kit/sd/consul"
	"github.com/hashicorp/consul/api"
)

var Instancer *consul.Instancer

func init(){
	config := api.DefaultConfig()
	config.Address = "127.0.0.1:8500"

	apiClient, cErr := api.NewClient(config)
	if cErr != nil{
		fmt.Println(cErr)
		return 
	}

	client := consul.NewClient(apiClient)

	var logger log.Logger
	{
		logger = log.NewLogfmtLogger(os.Stdout)
	}

	tags := []string{"primary"}
	Instancer = consul.NewInstancer(client, logger, "studentservice", tags, true)

}
